// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

namespace SnapObjects.Data
{
    internal class HavingElement : SqlElement
    {
        public HavingElement(string clause, string name)
            : this(null, SqlOperator.Equals, clause, SqlRightType.Clause, name)
        {

        }

        public HavingElement(
            string left, SqlOperator sqlOperator, object right, SqlRightType rightType, string name = "")
            : this(new ConditionElement(left, sqlOperator, right, rightType, name, true))
        {

        }

        public HavingElement(ConditionElement condition) : base(condition.ElementName)
        {
            this.Condition = condition;
        }

        public override SqlElementType ElementType => SqlElementType.Having;

        public ConditionElement Condition { get; }

        public override SqlElement Clone()
        {
            return new HavingElement(
                (ConditionElement)this.Condition.Clone());
        }
    }
}
